{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-07-24T14:46:25.538529Z",
     "iopub.status.busy": "2024-07-24T14:46:25.538280Z",
     "iopub.status.idle": "2024-07-24T14:46:25.545724Z",
     "shell.execute_reply": "2024-07-24T14:46:25.545041Z",
     "shell.execute_reply.started": "2024-07-24T14:46:25.538501Z"
    },
    "frozen": false,
    "init_cell": true,
    "tags": [
     "safe_output"
    ]
   },
   "source": [
    "# Autoloading\n",
    "\n",
    "Loading graph visualisation settings."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "init_cell": true
   },
   "outputs": [],
   "source": [
    "%%capture \"Remove this line to see debug information\"\n",
    "%%graph_notebook_vis_options\n",
    "{\n",
    "  \"edges\": {\n",
    "    \"smooth\": {\n",
    "      \"enabled\": true,\n",
    "      \"type\": \"dynamic\"\n",
    "    },\n",
    "    \"arrows\": {\n",
    "      \"to\": {\n",
    "        \"enabled\": true,\n",
    "        \"type\": \"arrow\"\n",
    "      }\n",
    "    }\n",
    "  }\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "frozen": false,
    "tags": [
     "unsafe_output"
    ]
   },
   "source": [
    "# Initial Setup\n",
    "\n",
    "## Get a view of all Ingested Cluster\n",
    "\n",
    "Retrieve all the current cluster ingested in KubeHound with the associated runID with the number of nodes. This numbers can be used to get a clue of the size of the cluster and also identify if an ingestion did not complete."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-07-24T14:46:28.273187Z",
     "iopub.status.busy": "2024-07-24T14:46:28.272852Z",
     "iopub.status.idle": "2024-07-24T14:46:28.625859Z",
     "shell.execute_reply": "2024-07-24T14:46:28.625126Z",
     "shell.execute_reply.started": "2024-07-24T14:46:28.273156Z"
    },
    "frozen": false,
    "init_cell": true,
    "tags": [
     "safe_output"
    ]
   },
   "outputs": [],
   "source": [
    "%%gremlin -d class -g critical -le 50 -p inv,oute\n",
    "\n",
    "kh.nodes()\n",
    "    .groupCount()\n",
    "    .by(project('cluster','runID')\n",
    "         .by('cluster').by('runID'))\n",
    "    .unfold()\n",
    "    .limit(1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "frozen": false,
    "tags": [
     "unsafe_output"
    ]
   },
   "source": [
    "## Setting your run_id/cluster\n",
    "\n",
    "Set which runID you want to use. The variable are being shared with all users of the instance, so we advise to make a uniq string for your user `runID_yourid` to avoid any conflict."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "frozen": false,
    "tags": [
     "safe_output"
    ]
   },
   "outputs": [],
   "source": [
    "%%gremlin -d class -g critical -le 50 -p inv,oute\n",
    "\n",
    "graph.variables()\n",
    "    .set('runID_yourid','01htdgjj34mcmrrksw4bjy2e94')"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Initialization Cell",
  "kernelspec": {
   "display_name": "Python 3 (default)",
   "language": "python",
   "name": "ipykernel-default"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
